*******************************************************************************
******************* REPLICATION DO-FILE FOR THE PAPER: ************************
** WHY ALL THESE PROMISES? HOW PARTIES STRATEGICALLY USE COMMITMENTS TO GAIN **
****** CREDIBILITY IN AN INCREASINGLY COMPETITIVE POLITICAL LANDSCAPE *********
*********** (PUBLISHED IN EUROPEAN JOURNAL OF POLITICAL RESEARCH) *************
*******************************************************************************
cd "C:\Users\replication" // Change this to the folder on your computer in which you have placed the replication files

global type "groups" // This should be changed to "allsimple" in order to run the robustness test 1 for all issues without grouping cmp-codes

**# PARTYFACTS_ID
copy "https://partyfacts.herokuapp.com/download/external-parties-csv/" "partyfacts-mapping.csv", replace
insheet using "partyfacts-mapping.csv", clear
keep if inlist(dataset_key, "parlgov", "manifesto")
destring dataset_party_id, replace
save "partyfacts.dta", replace

**# COMPARATIVE MANIFESTO PROJECT
*CMP categories
import excel using "cmp.xlsx", firstrow clear
save "cmp.dta", replace

*Importing dataset
copy "https://manifesto-project.wzb.eu/down/data/2020b/datasets/MPDataset_MPDS2020b_stata14.dta" "MPDataset_MPDS2020b_stata14.dta", replace // You might have to login on the manifesto project's webpage before you can download the file
use "MPDataset_MPDS2020b_stata14.dta", clear

keep country countryname per* party partyname partyabbrev date total parfam
rename (pervote peruncod) (vote per999)
rename (country countryname party per*) (country_num country dataset_party_id share*)

reshape long share, i(dataset_party_id date) j(cmp_code) string

*Grouping cmp_code to issues (using the grouping defined by $type)
g type = "$type"
merge m:1 type cmp_code using "cmp.dta", gen(_cmp) keepusing() // keep(master match)

*Adding partyfacts_id 
g dataset_key = "manifesto"
merge m:1 dataset_key dataset_party_id using "partyfacts.dta" , keep(master match) gen(_pfmanifesto) keepusing(partyfacts_id) // keep(match)

g pf_common_id = partyfacts_id
	replace pf_common_id = dataset_party_id if pf_common_id == .
	
*Number of sentences within each issue
g sentences_del = round(total/100*share)
bys pf_common_id date cmp_code: egen new_sentences_del = total(sentences_del), missing // If there is more than one manifesto under the same pf_common_id (combining partyfacts id & manifesto id), I sum their sentences together
bys pf_common_id date cmp_code: gen n = _n
keep if n == 1

bys country pf_common_id date issue: egen sentences = total(new_sentences_del), missing
egen tag = tag(country pf_common_id date issue)
keep if tag == 1

*Generating saliency change variable
g Saliencyornot = 1 if sentences>0 & sentences<.
	replace Saliencyornot = 0 if sentences==0
g SaliencyLog = log((sentences + 1)/total)

bysort pf_common_id issue (date):  g timebetween = date - date[_n-1]
bysort pf_common_id issue (date):  g SaliencyLogChange = SaliencyLog - SaliencyLog[_n-1]
	replace SaliencyLogChange = . if timebetween>1000 // Missing observation if the most recent available saliency data on previous elections is more than ten years before
bysort pf_common_id issue (date):  g LSaliencyornot = Saliencyornot[_n-1]
	replace LSaliencyornot = . if timebetween>1000

*Mainstream versus niche parties
g mainstream = 1 if inlist(parfam, 30, 40, 50, 60)
	replace mainstream = 0 if inlist(parfam, 10, 20, 70, 80, 90, 95)

keep country pf_common_id partyname partyabbrev issue date mainstream SaliencyLog SaliencyLogChange LSaliencyornot
	
save "manifesto.dta", replace


**# PARLGOV
**# - Main dataset
copy "https://dataverse.harvard.edu/api/access/datafile/10437088" "view_cabinet.tab", replace // Version: 2024-08-12)
import delimited "view_cabinet.tab", clear encoding(UTF-8) // 
	append using "us.dta" // Adding US data (president status) to parlgov dataset 
	rename (country_name party_id) (country dataset_party_id)
	
*Date variables
g election_date_num = date(election_date, "YMD")
g start_date_num = date(start_date, "YMD")
keep if election_date_num>0

save "view_cabinet.dta", replace 

**# - All parties in each country
use "view_cabinet.dta", replace 
egen party_each = tag(country dataset_party_id)
keep if party_each==1
keep country dataset_party_id
save "parties.dta", replace

**# - All elections in each country
use "view_cabinet.dta", replace 
egen election_each = tag(country election_date_num)
keep if election_each==1
keep country election_date_num

*Next election
bys country (election_date_num): g election_date_num_next = election_date_num[_n + 1]
g date_next = year(election_date_num_next) * 100 + month(election_date_num_next)

save "elections.dta", replace

**# - All governments in each country
use "view_cabinet.dta", replace 

egen government_each = tag(country election_date_num start_date_num)
keep if government_each==1
keep country election_date_num start_date_num

*Number of governments within election period
bys country election_date_num (start_date_num): g gov = _n

*Last government before election 
bys country election_date_num: egen gov_last = max(gov)

*Saving
save "governments.dta", replace


**# - Merging  parlgov-files
use "governments.dta", replace
merge m:1 country election_date_num using "elections.dta",  nogen
joinby country using "parties.dta"
merge 1:1 country election_date_num start_date dataset_party_id using "view_cabinet.dta", keepusing(cabinet_party election_date dataset_party_id)

*Adding partyfacts_id 
g dataset_key = "parlgov"
merge m:1 dataset_key dataset_party_id using "partyfacts.dta", keep(master using match) gen(_pfparlgov) keepusing(partyfacts_id) // keep(match)
	replace partyfacts_id = 432 if dataset_party_id == 9998 // US: Democratic Party
	replace partyfacts_id = 809 if dataset_party_id == 9999 // US: Republican Party
		
g pf_common_id = partyfacts_id
	replace pf_common_id = dataset_party_id if pf_common_id == .

bys country election_date_num start_date pf_common_id (cabinet_party): g n = _n
keep if n == 1 

*Cabinet party last government before election
g cabinet_party_simple = 0 if inlist(cabinet_party, ., 0)
	replace cabinet_party_simple = 1 if inlist(cabinet_party, 1)
	
*Government status just before the election
g gov_before_election = 1 if gov==gov_last
keep if gov_before_election == 1

*Saving
save "parlgov.dta", replace

**# POLCOMMIT
copy "https://dataverse.harvard.edu/api/access/datafile/10803131" "polcommit_v1.0.tab", replace
import delimited "polcommit_v1.0.tab", clear encoding(UTF-8) // 

*Adding partyfacts_id 
rename (party countryname) (dataset_party_id country)
g dataset_key="manifesto"
merge m:1 dataset_key dataset_party_id using "partyfacts.dta", keep(master match) gen(_pfpolcommit) keepusing(partyfacts_id) // keep(match)

g pf_common_id = partyfacts_id
	replace pf_common_id = dataset_party_id if pf_common_id == .

*CMP-categories
replace cmp_code = subinstr(cmp_code, ".", "_", .) if cmp_code!="."
replace cmp_code = "000" if inlist(cmp_code, "NA", "0")

g type = "$type"
merge m:1 type cmp_code using "cmp.dta", keepusing(cmprecode) keep(master match) gen(merge1) // Adding adjusted cmp categories to master dataset to correctly merge with issue categories in manifesto data
replace cmp_code = cmprecode // 
merge m:1 type cmp_code using "cmp.dta", keepusing(issue) keep(match master) gen(merge2)

* Each sentence gets the value 1
g one = 1

*Total number of quasi-sentences within each party and within each issue
bys country pf_common_id date: egen p_sentences = total(one)
bys country pf_common_id date issue: egen i_sentences = total(one)

*Total number of commitments within each party and within each issue
bysort country pf_common_id date: egen p_commitment = total(commitment==1)
bys country pf_common_id date issue: egen i_commitment = total(commitment==1)

*Share of commitments within each party and within each issue
g sh_p_commitment = p_commitment/p_sentences*100
g sh_i_commitment = i_commitment/i_sentences*100
	replace sh_i_commitment = 0 if sh_i_commitment == .

egen issue_level = tag(country pf_common_id date issue)
keep if issue_level==1
keep country pf_common_id date issue p_sentences i_sentences sh_p_commitment p_commitment sh_i_commitment i_commitment

save "polcommit.dta", replace


**# CPDS
copy "https://cpds-data.org/wp-content/uploads/2023/10/cpds_1960-2020_update_2022.zip" "cpds_1960-2020_update_2022.zip", replace
unzipfile "cpds_1960-2020_update_2022.zip", ifilter(`"(.*\.(do|dta)$)"')
*copy "CPDS_1960-2020_Update_2022.dta" "CPDS_1960-2020_Update_2022.dta", replace
*erase "CPDS_1960-2020_Update_2022.dta"
use "CPDS_1960-2020_Update_2022.dta", clear

* Country name
replace country = "United States" if country=="USA"

* Key variable
g parl = 1 if pres==0
	replace parl = 0 if inlist(pres, 1,2,3,4)

* Saving
save "cpds.dta", replace


**# MERGING THE DATASETS
use "manifesto.dta", clear

merge 1:1 country date pf_common_id issue using "polcommit.dta", gen(_polcommit)  // keep(match using)

*Zero commitments on issues on which the party did not mention in the manifesto
bys country pf_common_id date: egen included = total(_polcommit==3)
	replace sh_i_commitment = 0 if sh_i_commitment==. & included!=0
	replace i_commitment = 0 if i_commitment==. & included!=0

*Only merging with one party per election from the parlgov dataset
g date_next = date
g gov_before_election = 1

merge m:1 country date_next pf_common_id gov_before_election using "parlgov.dta", gen(_parlgov)

g year = floor(date / 100)

merge m:1 country year using "cpds.dta", gen(_cpds)

encode issue, g(issue_num)
encode country, g(country_num)

egen party_level = tag(country pf_common_id date_next) if sh_p_commitment!=. 

save "analysis $type.dta", replace


**# ANALYSIS
use "analysis groups.dta", replace

su sh_p_commitment if party_level==1, detail // Is variance larger than mean?

eststo model1_1: nbreg sh_p_commitment year effpar_ele i.mainstream i.cabinet_party_simple i.parl i.gov_type if party_level==1, vce(robust) irr

g esample1=1 if e(sample)==1
tab country_num if e(sample)==1
estadd scalar n_countries = r(r)

save "analysis part 1.dta", replace

su year if esample1==1, detail
margins, at(year=(`r(min)' (5) `r(max)'))
marginsplot,  scheme(s1mono) xtitle(" ""Year") ytitle("Predicted share of commitments" "(within manifestoes)" " ") xlabel(, labsize(small)) xlabel(1984 (5) 2019) title("") note("", size(vsmall)) recastci(rline) ciopts(lpattern(dash)) recast(line) ylabel(6 "6%" 7 "7%" 8 "8%" 9 "9%" 10 "10%" 11 "11%" 12 "12%" 13 "13%" 14 "14%" 15 "15%" 16 "16%" 17 "17%" 18 "18%" 19 "19%" 20 "20%" 21 "21%" 22 "22%" 23 "23%" 24 "24%", angle(360) grid labsize(small))
graph export "model 1 - year.png", replace

su effpar_ele if esample1==1, detail
margins, at(effpar_ele=(`r(min)' (0.5) `r(max)'))
marginsplot,  scheme(s1mono) xtitle(" ""Effective number of parties") ytitle("Predicted share of commitments" "(within manifestoes)" " ") xlabel(, labsize(small)) xlabel(2 (1) 6) title("") note("", size(vsmall)) recastci(rline) ciopts(lpattern(dash)) recast(line) ylabel(8 "8%" 10 "10%" 12 "12%" 14 "14%" 16 "16%" 18 "18%" 20 "20%" 22 "22%" 24 "24%" 26 "26%" 28 "28%" 30 "30%" 32 "32%" 34 "34%" 36 "36%" 38 "38%" 40 "40%", angle(360) grid labsize(small))
graph export "model 1 - ENP.png", replace

margins, at(mainstream=(0 1))
marginsplot,  scheme(s1mono) xlabel(0 "Niche party" 1 "Mainstream party", labsize(small)) ytitle("Predicted share of commitments" "(within manifestoes)" " ") title("") note("", size(vsmall)) xscale(range(-0.5 1.5)) yscale(range(16 21.5))  recast(scatter) ylabel(8 "8%" 10 "10%" 12 "12%" 14 "14%" 16 "16%" 18 "18%" 20 "20%" 22 "22%" 24 "24%", angle(360) grid labsize(small)) xtitle(" ")
graph export "model 1 - mainstream.png", replace


*Issue level
use "analysis groups.dta", replace

su sh_i_commitment, detail // Is variance larger than mean?
eststo model1_2: poisson sh_i_commitment c.SaliencyLogChange year effpar_ele i.mainstream i.cabinet_party_simple i.parl i.gov_type i.LSaliencyornot SaliencyLog i.issue_num if !inlist(issue, "None", "Political authority"),  vce(robust) 
estat gof // Significant = use nbreg instead

eststo model1_2: nbreg sh_i_commitment c.SaliencyLogChange year effpar_ele i.mainstream i.cabinet_party_simple i.parl i.gov_type i.LSaliencyornot SaliencyLog i.issue_num if !inlist(issue, "None", "Political authority"), irr vce(robust) difficult

g esample2 = 1 if e(sample)==1
tab country_num if e(sample)==1
estadd scalar n_countries = r(r)

save "analysis part 2.dta", replace

label var sh_i_commitment " "
esttab model1_1 model1_2 using "table with results.rtf", replace ///
	eform varwidth(30)  cells(b(star fmt(a2)) se(par fmt(a2)))  collabels("" "") nonumbers nonotes star(* 0.05 ** 0.01 *** 0.001) label se ///
	stats(N r2_p n_countries, labels("Observations" "Pseudo R-squared" "Number of countries" ))  ///
	title("Table 3: The policy-committing strategy and its causes") ///
	addnotes("Notes: *p<0.05, **p<0.01, ***p<0.001. Based on negative binomial regression models with robust standard errors. The beta-coefficients illustrate the incidence rate ratios (the constant is the baseline incidence rate). Coefficients of issue dummies are not shown (only used in model II).") ///
	mtitles("Model I: Manifesto level" "Model II: Issue level") ///
	order(year effpar_ele 1.mainstream SaliencyLogChange) ///
	refcat(13.country "Country" 2.gov_type "Government type (ref = single-party majority government)", label(" ")) ///
	drop(0.mainstream 0.cabinet_party_simple 0.parl 0.LSaliencyornot 1.gov_type *issue_num lnalpha) ///
	varlabels(SaliencyLogChange "Saliency change" SaliencyLog "Saliency" effpar_ele "Effective number of parties" 1.mainstream "Mainstream party (ref = niche party)" 1.cabinet_party_simple "Government party (ref = opposition party)" 1.parl "Parliamentary system (ref = presidential, semi-presidential or hybrid system)" 1.LSaliencyornot "Issue engagement at previous election (ref = issue avoidance)" 2.gov_type "- Minimal winning coalition" 3.gov_type "- Surplus coalition" 4.gov_type "- Single-party minority government" 5.gov_type "- Multi-party minority government" 6.gov_type "- Caretaker government" 7.gov_type "- Technocratic government" year "Year" _cons "Constant")

su SaliencyLogChange if esample2==1, detail
local rdec: display %5.2f `r(p10)'
local rinc: display %5.2f `r(p90)'
di `rdec' "  " `rinc'
margins, at(SaliencyLogChange=(`rdec' (0.2) `rinc'))
marginsplot,  scheme(s1mono) xlabel(`rdec' `""High decrease""in saliency""' -1.2 " " -1.0 " " -0.8 " " -0.6 " " -0.4 " " -0.2 " "  0 `""No change" "in saliency""' 0.2 " "  0.4 " "  0.6 " "  0.8 " " 1.0 " " 1.2 " " `rinc' `""High increase""in saliency""' , labsize(small)) xtitle(" ") ytitle("Predicted share of commitments" "(within issues)" " ") title("") note("", size(vsmall)) xscale(range(-1.5 1.5)) yscale(range(16 21.5)) recastci(rline) ciopts(lpattern(dash)) recast(line) ylabel(10 "10%" 11 "11%" 12 "12%" 13 "13%" 14 "14%" 15 "15%" 16 "16%" 17 "17%" 18 "18%" 19 "19%" 20 "20%" 21 "21%", angle(360) grid labsize(small))
graph export "model 2 - saliency change.png", replace

*Robustness tests 1 - all issues
if fileexists("analysis allsimple.dta") == 1 {
use "analysis allsimple.dta", replace

eststo model2_1: nbreg sh_i_commitment c.SaliencyLogChange year effpar_ele i.mainstream i.cabinet_party_simple i.parl i.gov_type i.LSaliencyornot SaliencyLog i.issue_num if !inlist(issue, "None", "Political authority"), irr vce(robust) difficult
g esamplerobust1 = 1
tab country_num if e(sample)==1
estadd scalar n_countries = r(r)

save "robust 1.dta", replace


esttab model2_1 using "robust 1.rtf", replace eform ///
	varwidth(30)  cells(b(star fmt(a2)) se(par fmt(a2)))  collabels("" "") nonumbers nonotes star(* 0.05 ** 0.01 *** 0.001) label se ///
	stats(N r2_p n_countries, labels("Observations" "Pseudo R-squared" "Number of countries" ))  ///
	title("Table C2: The policy-committing strategy and its causes - minimal grouping of issues") ///
	addnotes("Notes: *p<0.05, **p<0.01, ***p<0.001. Based on negative binomial regression models with robust standard errors. Coefficients of issue dummies are not shown (only used in model II).") ///
	mtitles("Model I: Issue level") ///
	order(year effpar_ele 1.mainstream SaliencyLogChange) ///
	refcat(13.country "Country" 2.gov_type "Government type (ref = single-party majority government)", label(" ")) ///
	drop(0.mainstream 0.cabinet_party_simple 0.parl 0.LSaliencyornot 1.gov_type *issue_num lnalpha) ///
	varlabels(SaliencyLogChange "Saliency change" SaliencyLog "Saliency" effpar_ele "Effective number of parties" 1.mainstream "Mainstream party (ref = niche party)" 1.cabinet_party_simple "Government party (ref = opposition party)" 1.parl "Parliamentary system (ref = presidential, semi-presidential or hybrid system)" 1.LSaliencyornot "Issue engagement at previous election (ref = issue avoidance)" 2.gov_type "- Minimal winning coalition" 3.gov_type "- Surplus coalition" 4.gov_type "- Single-party minority government" 5.gov_type "- Multi-party minority government" 6.gov_type "- Caretaker government" 7.gov_type "- Technocratic government" year "Year" _cons "Constant")
}

*Robustness tests 2 - real count model with exposure variable
use "analysis part 1.dta", replace
eststo model3_1: nbreg p_commitment year effpar_ele i.mainstream i.cabinet_party_simple i.parl i.gov_type, exp(p_sentences) vce(robust) irr
use "analysis part 2.dta", replace
eststo model3_2: nbreg i_commitment year effpar_ele i.mainstream c.SaliencyLogChange SaliencyLog LSaliencyornot i.cabinet_party_simple i.parl i.gov_type i.issue_num, vce(robust) exp(i_sentences) irr // Issue level: Country and party controls

esttab model1_1 model1_2 using "robust 2.rtf", replace ///
	eform varwidth(30)  cells(b(star fmt(a2)) se(par fmt(a2)))  collabels("" "") nonumbers nonotes star(* 0.05 ** 0.01 *** 0.001) label se ///
	stats(N r2_p n_countries, labels("Observations" "Pseudo R-squared" "Number of countries" ))  ///
	title("Table G2: The policy-committing strategy (measured as a count variable) and its causes") ///
	addnotes("Notes: *p<0.05, **p<0.01, ***p<0.001. Based on negative binomial regression models with robust standard errors. The beta-coefficients illustrate the incidence rate ratios (the constant is the baseline incidence rate). Coefficients of issue dummies are not shown (only used in model II).") ///
	mtitles("Model I: Manifesto level" "Model II: Issue level") ///
	order(year effpar_ele 1.mainstream SaliencyLogChange) ///
	refcat(13.country "Country" 2.gov_type "Government type (ref = single-party majority government)", label(" ")) ///
	drop(0.mainstream 0.cabinet_party_simple 0.parl 0.LSaliencyornot 1.gov_type *issue_num lnalpha) ///
	varlabels(SaliencyLogChange "Saliency change" SaliencyLog "Saliency" effpar_ele "Effective number of parties" 1.mainstream "Mainstream party (ref = niche party)" 1.cabinet_party_simple "Government party (ref = opposition party)" 1.parl "Parliamentary system (ref = presidential, semi-presidential or hybrid system)" 1.LSaliencyornot "Issue engagement at previous election (ref = issue avoidance)" 2.gov_type "- Minimal winning coalition" 3.gov_type "- Surplus coalition" 4.gov_type "- Single-party minority government" 5.gov_type "- Multi-party minority government" 6.gov_type "- Caretaker government" 7.gov_type "- Technocratic government" year "Year" _cons "Constant")

*Length of manifestoes over time
use "analysis part 1.dta", replace

tw lfit p_sentences year if esample1==1 || scatter p_sentences year if esample1==1, msize(tiny) ytitle("Number of""quasi-sentences") xtitle("Election year") legend(off) 

*Compare number of Q-S with number of Q-S with commitments (also for shares)
use "analysis part 2.dta", replace

lowess i_commitment i_sentences if esample2==1, msize(tiny)  ytitle("Number of quasi-sentences""that includes commitments (within issue) ") xtitle("Number of quasi-sentences on issue") title(" ") note(" ")
graph export "lowess - numeric.png", replace

lowess sh_i_commitment SaliencyLog if esample2==1, msize(tiny)  ytitle("Percentage share of quasi-sentences""including commitments (within issue) ") xtitle("Share of quasi-sentences on issue""using Lowe et al. (2011)'s logarithmic measure") title(" ") note(" ")
graph export "lowess - share.png", replace


*Descriptive statistics
use "analysis part 1.dta", replace

estpost tabstat  sh_p_commitment year effpar_ele mainstream cabinet_party_simple parl if esample1==1, statistics(mean sd min max) columns(statistics)

esttab . using "analysis part 1 - descriptive.rtf", cells("mean(fmt(a2)) sd(fmt(a2)) min(fmt(a2)) max(fmt(a2))") label varwidth(20) nonumber unstack noobs collabels("Mean" "SD" "Min" "Max") replace modelwidth(12) title(Table F1: Mean, standard deviation, minimum, and maximum (Model I from main analysis))

use "analysis part 2.dta", replace

estpost tabstat  sh_i_commitment year effpar_ele mainstream SaliencyLogChange SaliencyLog LSaliencyornot cabinet_party_simple parl if esample2==1, statistics(mean sd min max) columns(statistics)

esttab . using "analysis part 2 - descriptive.rtf", cells("mean(fmt(a2)) sd(fmt(a2)) min(fmt(a2)) max(fmt(a2))") label varwidth(20) nonumber unstack noobs collabels("Mean" "SD" "Min" "Max") replace modelwidth(12) title(Table F2: Mean, standard deviation, minimum, and maximum (Model II from main analysis))

*Number of sentences coded, number of election programmes, and included issues
use "analysis part 2.dta", replace

egen totalsentences = total(i_sentences) if esample2==1
tab totalsentences

use "analysis part 1.dta", replace
egen electionprogram = tag(country dataset_party_id date) if esample1==1
tab electionprogram

bysort electionprogram country (year partyname): g num1 = _n
bysort electionprogram country year (partyname): g num2 = _n
sort electionprogram country year partyname
replace country = "" if num1!=1
tostring year, replace
replace year = "" if num2!=1
browse country partyname year num1 num2  if electionprogram==1
keep if electionprogram==1
rename (country year partyname) (Country Year Party)
export excel Country Year Party using "included.xlsx", replace firstrow(variables)


use "analysis part 2.dta", replace
levelsof issue if esample2==1, local(is)
use "cmp.dta", replace
order issue cmp_code name
sort issue cmp_code
g keep = .
foreach i of local is {
	replace keep = 1 if type == "groups" & issue == "`i'"
}
keep if keep == 1
export excel issue cmp_code name  using "all issues.xlsx", replace firstrow(variables)

levelsof issue, local(li)
local b = 0
foreach i of local li {
	local a "`a', `i'"
	local `b++'
}
di "`a'"
di `b'


if fileexists("analysis allsimple.dta") == 1 {
use "robust 1.dta", replace
levelsof issue if esamplerobust1==1, local(is)
use "cmp.dta", replace
order issue cmp_code name
sort issue cmp_code
g keep = .
foreach i of local is {
	replace keep = 1 if type == "allsimple" & issue == "`i'"
}
keep if keep == 1
export excel issue cmp_code name  using "all issues - robust 1.xlsx", replace firstrow(variables)

levelsof issue, local(li)
local b = 0
foreach i of local li {
	local a "`a', `i'"
	local `b++'
}
di "`a'"
di `b'
}

*Bargaining time over time
copy "https://repdem.org/index.php/download/91/basic-data-europe/4218/paged-basic.dta" "paged.dta", replace 
use "paged.dta", clear

gen year = year(elecdate)
bysort country_name: egen max = max(year)
bysort country_name: egen min = min(year)
egen tag = tag(country_name)
g minyear = min >1989

collapse (mean) form_duration_alt , by(year)

lowess form_duration_alt year, ytitle("Number of days""before government formation") note("") xtitle(Year) title("")
graph export "bargaining.png", replace


*Comparison: Number of commitments versus number of objective pledges versus number of subjective pledges
use "analysis part 1.dta", replace
keep if esample1==1

replace partyabbrev = "FG" if partyname=="Family of the Irish"
replace partyabbrev = "FF" if partyname=="Soldiers of Destiny"

keep if party_level==1

save "number of commitments.dta", replace

import delimited "AJPS_CPPG_pledges_10April2017.tab", clear encoding(UTF-8) // Can be found on Harvard Dataverse: https://doi.org/10.7910/DVN/YJUIBI

*** Adding country names
rename country country_num
g country = ""
replace country = "United States" if country_num==1
replace country = "United Kingdom" if country_num==2
replace country = "Netherlands" if country_num==3
replace country = "Ireland" if country_num==4
replace country = "Sweden" if country_num==5
replace country = "Spain" if country_num==6
replace country = "Germany" if country_num==7
replace country = "Italy" if country_num==8
replace country = "Portugal" if country_num==9
replace country = "Bulgaria" if country_num==10
replace country = "Canada" if country_num==11
replace country = "Austria" if country_num==12

***Adding party names
g partyname = "" 
g partyfacts_id = .

*US
replace partyname = "Republican Party" if partyid == 101
replace partyfacts_id = 809 if partyid == 101
replace partyname = "Democratic Party" if partyid == 102
replace partyfacts_id = 432 if partyid == 102

*UK
replace partyname = "Conservative Party" if partyid == 201
replace partyfacts_id = 1567 if partyid == 201
replace partyname = "Labour Party" if partyid == 202
replace partyfacts_id = 1516 if partyid == 202

*NL
replace partyname = "PvdA" if partyid == 301
replace partyfacts_id = 1234  if partyid == 301
replace partyname = "D66" if partyid == 302
replace partyfacts_id = 45 if partyid == 302
replace partyname = "CDA" if partyid == 303
replace partyfacts_id = 1157 if partyid == 303
replace partyname = "VVD" if partyid == 304
replace partyfacts_id = 828 if partyid == 304

*IE
replace partyname = "FF" if partyid == 401
replace partyfacts_id = 1055 if partyid == 401
replace partyname = "FG" if partyid == 402
replace partyfacts_id = 1288 if partyid == 402
replace partyname = "Labour" if partyid == 403
replace partyfacts_id = 562 if partyid == 403
replace partyname = "PD" if partyid == 404
replace partyfacts_id = 924 if partyid == 404
replace partyname = "Workers Party" if partyid == 405
replace partyfacts_id = 208 if partyid == 405
replace partyname = "DL" if partyid == 406
replace partyfacts_id = 1172 if partyid == 406
replace partyname = "National Coalition" if partyid == 407
replace partyname = "Green" if partyid == 408
replace partyfacts_id = 1775 if partyid == 408
replace partyname = "SF" if partyid == 409
replace partyfacts_id = 4 if partyid == 409

*SE
replace partyname = "Vensterpartiet" if partyid == 501
replace partyfacts_id = 830 if partyid == 501
replace partyname = "Socialdemokraterna" if partyid == 502
replace partyfacts_id = 487 if partyid == 502
replace partyname = "Centerpartiet" if partyid == 503
replace partyfacts_id = 199 if partyid == 503
replace partyname = "Folkpartiet" if partyid == 504 
replace partyfacts_id = 1274 if partyid == 504
replace partyname = "Moderaterna" if partyid == 505
replace partyfacts_id = 690 if partyid == 505
replace partyname = "Kristdemokraterna" if partyid == 506
replace partyfacts_id = 651 if partyid == 506
replace partyname = "Miljøpartiet" if partyid == 507
replace partyfacts_id = 456 if partyid == 507
replace partyname = "Ny demokrati" if partyid == 508
replace partyfacts_id = 343 if partyid == 508
replace partyname = "Sverigedemokraterna" if partyid == 509
replace partyfacts_id = 409 if partyid == 509
replace partyname = "Allians for Sverige " if partyid == 510
replace partyname = "Rødgrøna" if partyid == 511

*ES
replace partyname = "PP" if partyid == 601
replace partyfacts_id = 441 if partyid == 601
replace partyname = "PSOE" if partyid == 602
replace partyfacts_id = 1338 if partyid == 602
replace partyname = "CiU" if partyid == 603
replace partyfacts_id = 139 if partyid == 603

*DE
replace partyname = "SPD" if partyid == 701
replace partyfacts_id = 383 if partyid == 701
replace partyname = "CDU/CSU" if partyid == 702
replace partyfacts_id = 211 if partyid == 702
replace partyname = "FDP" if partyid == 703
replace partyfacts_id = 573 if partyid == 703
replace partyname = "Green" if partyid == 704
replace partyfacts_id = 10 if partyid == 704
replace partyname = "Linke" if partyid == 705
replace partyfacts_id = 1545 if partyid == 705

*IT
replace partyname = "ProdiLleft" if partyid == 801
replace partyfacts_id = 1372 if partyid == 801
replace partyname = "Berlusconi/Right" if partyid == 802
replace partyfacts_id = 365 if partyid == 802 & year == 2008
replace partyfacts_id = 1626 if partyid == 802 & year == 2001

*PT
replace partyname = "PS" if partyid == 901
replace partyfacts_id = 655 if partyid == 901
replace partyname = "PSD" if partyid == 902
replace partyfacts_id = 1359 if partyid == 902
replace partyname = "CDS_PP" if partyid == 903
replace partyfacts_id = 1308 if partyid == 903
replace partyname = "CDU" if partyid == 904
replace partyfacts_id = 284 if partyid == 904
replace partyname = "BE" if partyid == 905
replace partyfacts_id = 1310 if partyid == 905

*BG
replace partyname = "Ataka" if partyid == 1001
replace partyfacts_id = 1793 if partyid == 1001
replace partyname = "BBB" if partyid == 1002
replace partyfacts_id = 1027 if partyid == 1002
replace partyname = "BNS" if partyid == 1003
replace partyfacts_id = 263 if partyid == 1003
replace partyname = "BSP" if partyid == 1004
replace partyfacts_id = 757 if partyid == 1004
replace partyname = "BZNS" if partyid == 1005
replace partyfacts_id = 2060 if partyid == 1005
replace partyname = "DPS" if partyid == 1006
replace partyfacts_id = 982 if partyid == 1006
replace partyname = "DSB" if partyid == 1007
replace partyfacts_id = 1195 if partyid == 1007
replace partyname = "EuroLeft" if partyid == 1008
replace partyfacts_id = 149 if partyid == 1008
replace partyname = "NDSV" if partyid == 1009
replace partyfacts_id = 374 if partyid == 1009
replace partyname = "ODS" if partyid == 1010
replace partyfacts_id = 1183 if partyid == 1010 
replace partyname = "ONS" if partyid == 1011
replace partyfacts_id = 1765 if partyid == 1011
replace partyname = "NS" if partyid == 1012
replace partyfacts_id = 747 if partyid == 1012
replace partyname = "UDF/SDS" if partyid == 1013
replace partyfacts_id = 482 if partyid == 1013
replace partyname = "GERB" if partyid == 1014
replace partyfacts_id = 760 if partyid == 1014
replace partyname = "SK" if partyid == 1015
replace partyfacts_id = 58 if partyid == 1015

*CA
replace partyname = "Canadian Alliance" if partyid == 1101
replace partyfacts_id = 1332 if partyid == 1101
replace partyname = "Bloc QuŽbŽcois" if partyid == 1102
replace partyfacts_id = 1428 if partyid == 1102
replace partyname = "Conservative Party of Canada" if partyid == 1103
replace partyfacts_id = 1004 if partyid == 1103
replace partyname = "Liberal Party of Canada" if partyid == 1104
replace partyfacts_id = 1739 if partyid == 1104
replace partyname = "New Democratic Party" if partyid == 1105
replace partyfacts_id = 152 if partyid == 1105
replace partyname = "Progressive Conservative Party of Canada" if partyid == 1106
replace partyfacts_id = 232 if partyid == 1106
replace partyname = "Reform Party of Canada" if partyid == 1107
replace partyfacts_id = 1757 if partyid == 1107

*AT
replace partyname = "OVP" if partyid == 1201
replace partyfacts_id = 1329 if partyid == 1201
replace partyname = "FPO" if partyid == 1202
replace partyfacts_id = 463 if partyid == 1202
replace partyname = "SPO" if partyid == 1203
replace partyfacts_id = 1384 if partyid == 1203
replace partyname = "BZO" if partyid == 1204 // I guess this is BZO, since it scores 1 on "opppreel"
replace partyfacts_id = 599 if partyid == 1204
replace partyname = "GRUNE" if partyid == 1205 // I guess this is GRUENE, since it scores 0 on "opppreel" and 0 on "outalways" (no government experience)
replace partyfacts_id = 1659 if partyid == 1205

*Collapsing
g pledge = 1 

rename partyname partyname2
drop if partyfacts_id==1428

collapse (sum) pledge, by(country partyfacts_id idmanifesto partyname2 year)

merge 1:1 country partyfacts_id year using "number of commitments.dta", keep(match) gen(_comm)

g dif = p_commitment - pledge

*graph bar r_futu_respownhighsum pledge, by(partyabbrev) over(year, label(angle(45))) legend(label(1 "Commitment") label(2 "Pledge"))

tostring year, g(year_str)
g partyabbrev_year_str = partyabbrev + " " + year_str

graph bar p_commitment pledge, by(country, note(" ") ) over(partyabbrev_year_str, label(angle(45) labsize(small))) legend(label(1 "Commitment") label(2 "Objective pledge") size(small)) nofill outergap(500) bargap(10) ytitle("Number of election promises", size(small)) ylabel(0 (200) 1600, labsize(small))
graph export "comparison - pledge v commitment.png", replace

